package com.liwenxu;

import android.util.Log;

import com.Exception.ConnectException;
import com.example.a2018.myapplication.MainApplication;
import com.tutk.IOTC.AVAPIs;

import java.util.HashMap;

/**
 * Created by 李文旭 on 2018/9/15.
 */

public class Connect {
    public static HashMap<Integer,Integer> avchannelMap=new HashMap<Integer,Integer>();
    public boolean isConnect=false;
    public static void getChannelId(String account,String password,int camerIndex) throws ConnectException {
        Log.d("kaishi","try connect");
        int avchannelID = AVAPIs.avClientStart(MainApplication.sessionId, account, password, 50, new int[1], 0);
        int count=0;
        Log.d("chonglian"," "+count);
        while(avchannelID<0&&count<=3)//尝试重连三次
        {
            Log.d("chonglian"," "+count);
            avchannelID = AVAPIs.avClientStart(MainApplication.sessionId,account, password, 30, new int[1], 0);
            count++;
        }
        if(avchannelID<0)
        {
            throw new ConnectException("连接设备失败,请重试",avchannelID);
        }
        else
        {
            avchannelMap.put(camerIndex,avchannelID);
        }
    }
}
